package com.bbs.action;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author CharChen
 * @e-mail piggsoft@163.com
 * @since 2013-4-23
 * @version 1.0
 */
public abstract class AbstractAction extends ActionSupport implements ServletRequestAware, ServletResponseAware, SessionAware{

	protected Map<String, Object> session;
	
	protected HttpServletResponse response;
	
	protected HttpServletRequest request;
	
	private String message;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6258332832066239045L;

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public void write(String s){
		try {
			response.getWriter().write(s);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public void writeJson(String s){
		try {
			response.setContentType("application/json; charset=utf-8");
			response.getWriter().write(s);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
